package com.pet.server.ext.action.find;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.service.ArticleService;
import com.pet.server.ext.util.JsonUtil;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;

public class Subject extends ActionBase{

	private Integer subject_size;

	public Subject(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {
       subject_size=NumberUtil.getInteger(params.getFieldValue("subject_size"), 1);
       
	}
	
	@Override
	public Result invokeService() throws ApiError {
		ArticleService articleService = new ArticleService();		
		Result result = new Result();
		List<com.pet.server.ext.data.Subject> list = articleService.querySubject(subject_size);
        JSONArray array = new JSONArray();
        for(com.pet.server.ext.data.Subject subject:list){
           JSONObject o = new JSONObject();
           o.put("id", subject.id);
           o.put("ico_path", subject.ico_path);
           o.put("title", subject.title);
           o.put("description", subject.description);
           o.put("create_time", JsonUtil.getTime(subject.created_time));
           array.add(o);
        }
        data.put("list", array);
        result.put("data", data);
	    return result;
	}
}
